<%@ page import="com.site.pojo.Receive" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/12/2
  Time: 11:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String opr =(String)application.getAttribute("detail");
    Receive receive = (Receive)application.getAttribute("receive");
    String receiveNumber = receive.getReceiveNumber();
    String receiveCount = receive.getReceiveCount().toString();
    String goodId = receive.getGoodsId().toString();
    String eid = receive.getEid().toString();
    String rid = receive.getRid().toString();
%>
<html>
<head>
    <title>入库明细</title>
    <link rel="stylesheet" href="/css/receive.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.min.js"></script>
    <script type="text/javascript">
        $(function () {
            init();
        })
        function init() {
            getAllDetail();
            getAll();
            getReceive();
        }
        function getAllDetail() {
            $.getJSON("/receiveDetail.do",{"opr":"getAllDetail"},function (data) {
                $("#table1 tbody").empty();
                $(data.data).each(function (i,o) {
                    $("#table1 tbody").append(
                        "<tr> " +
                        "<td width='200px'> "+
                        (i+1)+
                        "</td> <td width='400px'> " +
                        o.rtid+
                        "</td> <td width='300px'>" +
                        o.goodsId+
                        "</td> <td width='200px'>"+
                        o.receiveCount+""+o.unit+
                        "<td width='200px'> "+
                        "<a href='javascript:toUpdate("+JSON.stringify(o)+")'>修改</a>  "+
                        "<a href='javascript:deleteReceive("+JSON.stringify(o)+")'>删除</a> " +
                        "</td> </tr>");
                })
            })
        }
        function getAll() {
            $.getJSON("/viewwarehouse.do",{"opr":"getAll"},function (data) {
                if (data.code==200){
                    $("#tbody").empty();
                    $("#select").empty();
                    $(data.data).each(function(i,o){
                        $("#tbody").append(
                            "<tr> " +
                            "<td height='50px'>" +
                            o.rtid +
                            "</td>"+
                            "<td>" +
                            o.rid +
                            "</td>"+
                            "<td>" +
                            o.quantity +
                            "</td>"+
                            "<td>" +
                            o.neednum +
                            "</td>"+
                            "<td>" +
                            o.goodsid +
                            "</td>"+
                            "<td>" +
                            o.goods +
                            "</td>"+
                            "<td>" +
                            o.state +
                            "</td>"+
                            "<td>" +
                            "<a href='javascript:delgoods("+o.rid+")'>删除</a>&nbsp;&nbsp;&nbsp;<a href='javascript:upgoods("+JSON.stringify(o)+")'>修改</a>" +
                            "</td>"+
                            "</tr>");

                    $("#select").append(
                      "<label>货架"+
                       o.rid+
                      "<input type='radio' name='radio' value='"+o.rid+"'></label>"
                    );
                    })
                }
            })
        }
        function getReceive() {
            var opr = "<%=opr%>";
            var receiveNumber = "<%=receiveNumber%>";
            var receiveCount = <%=receiveCount%>;
            var goodsId = <%=goodId%>;
            var eid = <%=eid%>;
            if(opr==("true")){
                $("#detail").empty();
                $("#detail").append(
                    "<span style='color: red'> 当前待处理入库单编号："+
                        receiveNumber+
                      "&#160;&#160;待入库数量"+
                        "<span id='count'>"+ receiveCount+"</span>"+
                      "</span>"
                )
                console.log($("input[name='goodsId']")[0]);
             $("#goodsId").val(goodsId).attr("readonly","true");
            }else {

            }
        }
        function addDetail() {
            var form = $(".goodstop").serialize();
            $.getJSON("/receiveDetail.do",form,function (data) {
                if(data.code==200){
                    alert(data.message);
                    //总数
                    var countSum = $("#count").html();
                    //剩余
                    var fact = parseInt(countSum)-parseInt($("#total").val());
                    $("#total").val(fact);
                    if(parseInt(fact)<=0){
                        alert("当前选择货架入库完成！");
                        $.getJSON("/receiveDetail.do",{"opr":"delAppAttr"},function (data) {
                                     location.reload();
                        })
                    }
                }
            })
        }
    </script>
</head>
<body>
<div style="border: 1px solid #000000;width: 100%;height: 880px" >
    <form class="goodstop" style="width: 100%;text-align: center">
        <span>入库商品:</span> <input type="text" id="goodsId" name="goodsId" placeholder="请输入商品编号">
        <span>入库数量:</span> <input type="text" id="total" name="receiveCount" placeholder="请输入商品数量">
        <span>货架选择:</span> <span id="select"></span>
        <input name="opr" value="addDetail" type="hidden">
        <input name="rid" value="<%=rid%>" type="hidden">
        <br/><br/>
        <button  type="button" onclick="addDetail()">明细</button>
        <button  type="button" onclick="clearText()">清空</button>
        <button  type="button" onclick="clearText()">新增</button>
        <br/><br/>
        <div id="detail">

        </div>
        <%--<button  type="button" onclick="clearText()">导入商品</button>--%>
        <table style="text-align: center" id="table2">
            <thead>
            <tr>
                <th colspan="8">当前货架详情</th>
            </tr>
            <tr>
                <td width="200px">
                    仓库编号
                </td>
                <td width="300px">
                    货架编号
                </td>
                <td width="200px">
                    存放量
                </td>
                <td width="300px">
                    货架剩余
                </td>
                <td width="300px">
                    商品编号
                </td>
                <td width="300px">
                    商品
                </td>
                <td width="200px">
                    状态
                </td>
                <td width="300px">
                    操作
                </td>
            </tr>
            </thead>
            <tbody id="tbody">

            </tbody>
        </table>
    </form>
    <div class="goods">
        <table style="text-align: center" id="table1">
            <thead>
            <tr>
                <th colspan="5">入库明细单</th>
            </tr>
            <tr><!-- 1300px -->
                <td width="200px">
                    序号
                </td>
                <td width="400px">
                    货架编号
                </td>
                <td width="300px">
                    商品编号
                </td>
                <td width="200px">
                    入库数量
                </td>
                <td width="200px">
                    操作
                </td>
            </tr>
            </thead>
            <tbody id="tbody2">

            </tbody>
        </table>
    </div>
        <div class="goodspage">
            <ul id="pagination-digg" style="float: right">
                <li class="active">1</li>
                <li><a href="">2</a></li>
                <li><a href="">3</a></li>
                <li><a href="">4</a></li>
                <li><a href="">5</a></li>
                <li><a href="">6</a></li>
                <li><a href="">7</a></li>
                <li class="next"><a href="">Next &raquo;</a></li>
            </ul>
        </div>
    </div>
</div>
</body>
</html>
